<%@ page contentType="text/html;charset=UTF-8" %>

<!DOCTYPE html>
<html>
<head>
	<title>模块管理</title>
     <%@ include file="/common/meta.jsp" %>
	<%@ include file="/common/import.jsp" %>
	
	<script type="text/javascript">
	
		var sysEname='${sysEname}';
		
		$(function(){
			$('#unitList').datagrid({
				title:'审计模块列表',
				iconCls:'icon-ok',
				url:'list!data.action?&sysEname='+sysEname,
				nowrap: false,
				striped: true,
				collapsible:false,				
				fitColumns: true,
				pagination:true,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				pageList:[15,30,50],
				idField:'unitId',
				columns:[[
					{field:'sysEname',title:'所属应用',width:100},
					{field:'unitCname',title:'模块名称',width:100},
					{field:'unitEname',title:'模块标识',width:100},
					{field:'unitStatus',title:'状态',width:80,
						formatter:function(value){
							if( value=='1'){return '<font color=blue>启用</font>';}
						}
					},
					{field:'unitRemark',title:'备注',width:100}					
				]],				
				toolbar:[					
		          {		        	  
		              	text:'增加',
			              iconCls:'icon-add',
			              handler:function(){saveUnit();}
		        	  
		          },'-',
		          {
		              text:'删除',
		              iconCls:'icon-cut',
		              handler:function(){deleteunit();}		             
		          },'-',
		          {
		              text:'修改',
		              iconCls:'icon-edit',
		              handler:function(){editUnit();}
		          },
		          '-',
		           {
		              text:'刷新',
		              iconCls:'icon-reload',
		              handler:function(){
		                  reload();
		             }
		          }
		        ],
				onDblClickRow:function(row){
					saveunit('edit');
				}
			});
		});	
		
		// 增加模块
		function saveUnit(paraFlag){
			$('#unitAddFrame').html('');						
			var url = 'add.action?fatherId=&sysEname='+sysEname;
			$('#unitAddFrame').attr("src",url);
			$('#unitAddWin').window('open');			
		}
			
		// 修改模块	
		function editUnit(paraFlag){
			$('#unitAddFrame').html('');
			var node = getSelected();
			if(node){
				var unitId = node.unitId;
				var url = 'edit.action?id='+unitId;
				$('#unitAddFrame').attr("src",url);
				$('#unitAddWin').window('open');
			}
		}
		
		// 删除模块
		function deleteunit(){					
			var node = getSelected();	
			if(node){
		    	$.messager.confirm('确认','您确定要删除:<font color=red>'+node.unitCname+' </font>？',function(r){
		        	if(r){
						$.ajax({
							type: "post",
							url: "del.action?id="+node.unitId,
							success: function(data, textStatus){
								var result = jQuery.parseJSON(data);
							    if(result.flag=='T'){									
									$.messager.alert('结果', '操作成功', 'info',function(){
									var rowIndex = $('#unitList').datagrid('getRowIndex',node);								
									$('#unitList').datagrid('deleteRow', rowIndex);
									});
								}else{
									$.messager.alert('提交结果', "操作失败："+result.msg, 'error');
								}			
							},
							error: function(){
							//请求出错处理
							}
						});
		          	}
		       	});		             		
		    }	
		}
		
		// 判断修改、删除前是否选中记录
		function getSelected(){
			var selected = $('#unitList').datagrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		// 刷新列表
		function reload(){
			var node = $('#unitList').datagrid('getSelected');
			if (node){
				$('#unitList').datagrid('reload', node.unitId);
			} else {
				$('#unitList').datagrid('reload');
			}
		}
		
		// 关闭窗口
		function closeAdd(){
			$('#unitAddWin').window('close');
		}
		
		$('#unitAddWin').bind("close", reload);	
	</script>
</head>

<body>
	
	<table id="unitList"></table>
	
	<!-- 查询窗口 -->
	<div id="unitAddWin" class="easyui-window" title="信息" style="padding:5px;width: 550px;height:450;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   	 <iframe scrolling="yes" frameborder="0"  id="unitAddFrame" height="100%" width="100%" scrolling="No" frameborder="0" ></iframe>
    </div>
    
</body>
</html>